package com.designed.pattern.addition.strategyfactoryDecorate;

/**
 * todo 此类为2个功能类的结合，可以通过装饰模式优化掉
 *
 * @author yifei
 * @description 先打折在满减
 * @date 2024/1/3
 **/
public class CashReturnRebate implements ISale {
    private double moneyRebate = 1d;    // 打折
    private double moneyCondition = 0d;
    private double moneyReturn = 0d;

    public CashReturnRebate(double moneyRebate, double moneyCondition, double moneyReturn) {
        this.moneyRebate = moneyRebate;
        this.moneyCondition = moneyCondition;
        this.moneyReturn = moneyReturn;
    }

    @Override
    public double acceptCash(double price, int num) {
        double result = price * num * this.moneyRebate;
        if (moneyCondition > 0 && result >= moneyCondition) {
            result = result - Math.floor(result / moneyCondition) * moneyReturn;
        }
        return result;
    }
}
